
/**
*      author: Y_Yao
*      created: 2025-03-27 12:02:44
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int mod = 19650827;
const int N = 1e3 + 7;
int dp[N][N][2];//0左1右
int a[N];
int n;

void solve()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    if(n == 1)
    {
        cout << 1 << endl;
        return;
    }
    for(int i = 1;i <= n;i++)
    {
        dp[i][i][0] = 1;
    }
    for(int len = 1;len <= n;len++)
    {
        for(int i = 1,j = len + i;j <= n;j++,i++)
        {
            if(a[i] < a[i+1]) dp[i][j][0] += dp[i+1][j][0];//上一个状态从左边进入
            if(a[i] < a[j]) dp[i][j][0] += dp[i+1][j][1];//上一个状态从右边进入
            if(a[j] > a[j-1]) dp[i][j][1] += dp[i][j-1][1];//上一个状态从右边进入
            if(a[j] > a[i]) dp[i][j][1] += dp[i][j-1][0];//上一个状态从左边进入
            dp[i][j][1] %= mod;
            dp[i][j][0] %= mod;
        }
    }
    cout << (dp[1][n][1] + dp[1][n][0]) % mod << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}